export const menudata = [{
    id: '1',
    label: '首页',
    path: '/home/shouye'
}, {
    id: '2',
    label: '商品',
    children: [{
        id: '2-1',
        label: '商品列表',
        path: '/home/shoplist'
    }, {
        id: '2-2',
        label: '商品分页',
        path: '/home/addshop'
    }, {
        id: '2-3',
        label: '推荐商品',
        path: '/home/tuijianshop'
    }]
}, {
    id: '3',
    label: '轮播图管理',
    children: [{
        id: '3-1',
        label: '轮播图列表',
        path: '/home/list',
        children: [{
            id: '3-1-U',
            label: '修改轮播图状态'
        }, {
            id: '3-1-D',
            label: '删除轮播图状态'
        }, {
            id: "3-1-R",
            label: "轮播图列表显示"
        },]
    }, {
        id: '3-2',
        label: '轮播图添加',
        path: '/home/add'
    }]
}, {
    id: "4",
    label: '管理人员信息',
    children: [{
        id: '4-1',
        label: '操作人员列表',
        path: '/home/adminlist'
    }, {
        id: '4-2',
        label: '添加操作人员',
        path: '/home/addadmin'
    }]
}, {
    id: '6',
    label: '订单管理',
    children: [{
        id: '6-1',
        label: '订单列表',
        path: '/home/dingdanlist'
    },
    {
        id: '6-2',
        label: '筛选订单',
        path: '/home/changecity'
    }]
}, {
    id: '7',
    label: '地区管理',
    children: [{
        id: '7-1',
        label: '地区列表',
        path: '/home/dizhi'
    }]
}, {
    id: '8',
    label: '图像展示',
    children: [{
        id: '8-1',
        label: 'K线图',
        path: '/home/shujushow'
    }, {
        id: '8-2',
        label: '柱状图',
        path: '/home/shujushowz'
    }]
}]
export default function getMenus() {
    //  1）、获取该用户的权限（登录时已经保存了）
    let checkedKeys: string[] = [];// ['1','3','3-1']
    let currKeys = sessionStorage.getItem("grants");
    if (currKeys) {
        checkedKeys = JSON.parse(currKeys)
    }

    if (checkedKeys.length === 0) {
        checkedKeys = ['1', '2', '2-1', '2-2', '2-3', '3', '3-1', '3-2', '4', '4-1', '4-2', '5', '5-1', '6', '6-1', "6-2", '7', '7-1', "8", "8-1", '8-2'];
    }

    // 2）、根据该用户的权限结合全部菜单数据，产生该用户的菜单

    interface IMenuItem {
        id: string,
        label: string,
        path?: string,
        children?: IMenuItem[]
    }

    let currMenuData: IMenuItem[] = [];//存储当前用户的菜单项

    menudata.forEach(item => {
        if (checkedKeys.indexOf(item.id) > -1) {
            //定义一个菜单项：            
            const newmenuItem = { ...item };
            // 处理子一级
            if (item.children) {
                newmenuItem.children = [];
                item.children.forEach(sonItem => {
                    if (checkedKeys.indexOf(sonItem.id) > -1) {
                        newmenuItem.children?.push({ ...sonItem });
                    }
                })
            }
            currMenuData.push(newmenuItem);
        }
    });

    console.log("currMenuData", currMenuData);

    return currMenuData;

}